<?php
namespace app\api\controller;
use app\model\Problem as ProblemModel;
use app\model\Token as TokenModel;
use think\Db;


class Problem extends Base
{   
    protected $noCheckToken = ['index','read'];

    /**
     * @Author   CCH
     * @DateTime 2020-05-23T12:10:10+0800
     * @return   数据列表
     */
    public function index(){
        $user_id = $this->login_user['user_id'];
        $map_params = [
            ['key'=>'problem_bank_id','type'=>'='],
        ];
        $map = getSearchParam($map_params);
        if ( isSearchParam('keyword_search') ) {
            $map[] = ['name','like','%'.input('keyword_search').'%'];
        }

        $order_type = Db::raw('RAND() desc');

        $model = new ProblemModel();
        $page_param = ['page'=>input('page_index',1),'list_rows'=>input('page_size',10)];
        $list = $model->where($map)->order($order_type)->paginate($page_param)->toarray();
        foreach ($list['data'] as $k => $vo) {
           $list['data'][$k]['content'] = json_decode($vo['content'],true);
        }
        return apiResult('2000','获取成功',$list);
    }

    /**
     * 获取详情
     * @Author   cch
     * @DateTime 2020-05-26T17:22:45+0800
     * @return   [type]                   [description]
     */
    public function read($id){
        $model = new ProblemModel();
        $data = $model->where('id',$id)->find();
        if (!empty($data)) {
            
        }
        
        return apiResult('2000','获取成功',$data);
    }

   

   


}
